package com.homework.test20;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {


        //定义是数组
        Book[] books = new Book[3];

        //键盘输入
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < books.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个书的id:");
            int a = sc.nextInt();

            System.out.println("请输入第" + (i + 1) + "个书的书名:");
            String b = sc.next();

            System.out.println("请输入第" + (i + 1) + "个书的价格:");
            double c = sc.nextDouble();

            books[i] = new Book(a, b, c);
        }
        //冒泡排序法
        for (int i = 1; i < books.length; i++) {
            for (int j = 0; j < books.length - i; j++) {
                if (books[j].getPrice() > books[j + 1].getPrice()) {
                    Book temp = books[j];
                    books[j] = books[j + 1];
                    books[j + 1] = temp;
                }
            }
        }
        for (Book book : books) {
            System.out.println(book);
        }

    }
}
